package com.yigang.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yigang.dao.TheorderMapper;
import com.yigang.entity.OrderAndProduct;
import com.yigang.entity.Theorder;
import com.yigang.service.TheorderService;
import com.yigang.utils.ResultUtil;

@Service
@Transactional
public class TheorderServicelmpl implements TheorderService{
	@Autowired
	private TheorderMapper theorderMapper;

	@Override
	public ResultUtil selectTheorderList(Integer page, Integer limit, Theorder record) {
		// TODO Auto-generated method stub
		PageHelper.startPage(page,limit);
		List<Theorder> theorder = theorderMapper.selectTheorderList(record);
		PageInfo<Theorder> pageinfo = new PageInfo<Theorder>(theorder);
		ResultUtil resultUtil = new ResultUtil();
		resultUtil.setCode(0);
		resultUtil.setCount(pageinfo.getTotal());
		resultUtil.setData(pageinfo.getList());
		return resultUtil;
	}

	@Override
	public ResultUtil deleteByPrimaryKey(Integer theorderId) {
		// TODO Auto-generated method stub
		theorderMapper.deleteByPrimaryKey(theorderId);
		return ResultUtil.ok();
	}

	@Override
	public ResultUtil insertSelective(Theorder record) {
		// TODO Auto-generated method stub
		theorderMapper.insertSelective(record);
		return ResultUtil.ok();
	}

	@Override
	public ResultUtil updateByPrimaryKeySelective(Theorder record) {
		// TODO Auto-generated method stub
		theorderMapper.updateByPrimaryKeySelective(record);
		return ResultUtil.ok();
	}

	@Override
	public Theorder selectTheorderById(int theorderId) {
		// TODO Auto-generated method stub
		return theorderMapper.selectTheorderByid(theorderId);
	}

	@Override
	public OrderAndProduct selectOrderAndProduct(OrderAndProduct orderAndProduct) {
		List<OrderAndProduct> products = theorderMapper.selectOrderAndProduct(orderAndProduct);
		OrderAndProduct res = new OrderAndProduct();
		res.setAddress(products.get(0).getAddress());
		res.setName(products.get(0).getName());
		res.setPhone(products.get(0).getPhone());
		res.setTheorderId(products.get(0).getTheorderId());
		return res;
	}

	@Override
	public ResultUtil getTheorderDetails(Integer page, Integer limit, OrderAndProduct orderAndProduct) {
		PageHelper.startPage(page, limit);
		List<OrderAndProduct> products = theorderMapper.selectOrderAndProduct(orderAndProduct);
		PageInfo<OrderAndProduct> pageInfo = new PageInfo<OrderAndProduct>(products);
		ResultUtil resultUtil = new ResultUtil();
		resultUtil.setCode(0);
		resultUtil.setCount(pageInfo.getTotal());
		resultUtil.setData(pageInfo.getList());
		return resultUtil;
	}

}
